{% extends 'base.html' %}

{% block title %}{{ subproject.name }} - 子项目详情{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <!-- 子项目基本信息 -->
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h4 class="mb-0">
                        <i class="fas fa-tasks me-2"></i>{{ subproject.name }}
                    </h4>
                    <div class="btn-group">
                        <a href="{% url 'subprojects:subproject_edit' subproject.pk %}" class="btn btn-warning">
                            <i class="fas fa-edit me-1"></i>编辑子项目
                        </a>
                        {% if user.userprofile.role == 'admin' %}
                        <a href="{% url 'subprojects:subproject_status_update' subproject.pk %}" class="btn btn-success">
                            <i class="fas fa-sync me-1"></i>更新状态
                        </a>
                        {% endif %}
                        <a href="{% url 'subprojects:subproject_list' %}" class="btn btn-secondary">
                            <i class="fas fa-arrow-left me-1"></i>返回列表
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-borderless">
                                <tr>
                                    <th width="120">项目状态：</th>
                                    <td>
                                        <span class="badge fs-6
                                            {% if subproject.status == 'initial' %}bg-secondary
                                            {% elif subproject.status == 'approved' %}bg-success
                                            {% elif subproject.status == 'mid_check_passed' %}bg-info
                                            {% elif subproject.status == 'completed' %}bg-primary
                                            {% endif %}">
                                            {{ subproject.get_status_display }}
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <th>所属项目：</th>
                                    <td>
                                        <a href="{% url 'projects:project_detail' subproject.project.pk %}" 
                                           class="text-decoration-none">
                                            {{ subproject.project.name }}
                                        </a>
                                    </td>
                                </tr>
                                <tr>
                                    <th>负责人：</th>
                                    <td>{{ subproject.manager }}</td>
                                </tr>
                                <tr>
                                    <th>所属学院：</th>
                                    <td>{{ subproject.college.name }}</td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-6">
                            <table class="table table-borderless">
                                <tr>
                                    <th width="120">已使用经费：</th>
                                    <td>¥{{ subproject.used_budget|floatformat:2 }}</td>
                                </tr>
                                <tr>
                                    <th>团队成员：</th>
                                    <td>{{ subproject.team_members|default:"未填写" }}</td>
                                </tr>
                                <tr>
                                    <th>创建人：</th>
                                    <td>{{ subproject.created_by.get_full_name|default:subproject.created_by.username }}</td>
                                </tr>
                                <tr>
                                    <th>创建时间：</th>
                                    <td>{{ subproject.created_at|date:"Y-m-d H:i" }}</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    
                    {% if subproject.description %}
                    <div class="mt-3">
                        <h6><strong>子项目描述：</strong></h6>
                        <div class="bg-light p-3 rounded">
                            {{ subproject.description|linebreaks }}
                        </div>
                    </div>
                    {% endif %}
                </div>
            </div>

            <!-- 项目时间节点 -->
            <div class="card mb-4 info-card">
                <div class="card-header">
                    <h5 class="mb-0">
                        <i class="fas fa-clock me-2"></i>项目时间节点
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4">
                            <table class="table table-borderless">
                                <tr>
                                    <th width="120">立项时间：</th>
                                    <td>{{ subproject.project_start_date|date:"Y-m-d"|default:"未设置" }}</td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-4">
                            <table class="table table-borderless">
                                <tr>
                                    <th width="140">中期检查时间：</th>
                                    <td>{{ subproject.midterm_check_date|date:"Y-m-d"|default:"未设置" }}</td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-4">
                            <table class="table table-borderless">
                                <tr>
                                    <th width="120">结项时间：</th>
                                    <td>{{ subproject.project_end_date|date:"Y-m-d"|default:"未设置" }}</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 项目进度和统计 -->
            <div class="row">
                <div class="col-md-4">
                    <div class="card text-center">
                        <div class="card-body">
                            <i class="fas fa-chart-line fa-2x text-success mb-2"></i>
                            <h5 class="card-title">已使用经费</h5>
                            <h3 class="text-success">¥{{ subproject.used_budget|floatformat:2 }}</h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card text-center">
                        <div class="card-body">
                            <i class="fas fa-users fa-2x text-info mb-2"></i>
                            <h5 class="card-title">团队成员</h5>
                            <h3 class="text-info">{{ subproject.get_team_members_list|length }}</h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card text-center">
                        <div class="card-body">
                            <i class="fas fa-calendar fa-2x text-primary mb-2"></i>
                            <h5 class="card-title">项目进度</h5>
                            <h3 class="text-primary">{{ subproject.get_progress_percentage }}%</h3>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 项目信息概览 -->
            <div class="card mt-4">
                <div class="card-header">
                    <h5 class="mb-0">
                        <i class="fas fa-info-circle me-2"></i>项目信息概览
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <h6><strong>所属项目信息：</strong></h6>
                            <ul class="list-unstyled">
                                <li><strong>项目名称：</strong>{{ subproject.project.name }}</li>
                                <li><strong>学期：</strong>{{ subproject.project.get_semester_display_name }}</li>
                                <li><strong>教务负责人：</strong>{{ subproject.project.admin_manager.get_full_name|default:subproject.project.admin_manager.username }}</li>
                                <li><strong>项目总预算：</strong>¥{{ subproject.project.budget|floatformat:2 }}</li>
                            </ul>
                        </div>
                        <div class="col-md-6">
                            <h6><strong>子项目统计：</strong></h6>
                            <ul class="list-unstyled">
                                <li><strong>创建人：</strong>{{ subproject.created_by.get_full_name|default:subproject.created_by.username }}</li>
                                <li><strong>最后更新：</strong>{{ subproject.updated_at|date:"Y-m-d H:i" }}</li>
                                <li><strong>状态：</strong>{{ subproject.get_status_display }}</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}